package folderLogger.GUI;

import javax.swing.SwingWorker;

import folderLogger.FolderPrinter;
import folderLogger.OperationSettings;
import folderLogger.GUI.Delegates.CallbackDelegate;

public class ScanThreadHandler extends SwingWorker<Integer, Object> {
	
	private CallbackDelegate callback;
	private OperationSettings settings;
	private Integer status;
	private FolderPrinter folderPrinter;
	
	public ScanThreadHandler(CallbackDelegate callback, OperationSettings settings) {
		this.callback = callback;
		this.settings = settings;
		status = -1;
		folderPrinter = new FolderPrinter();
	}
	
    @Override
    public Integer doInBackground() {
    	callback.ExecuteWhenDone(false);
        status = folderPrinter.Run(settings);
        return status;
    }

    @Override
    protected void done() {
        callback.ExecuteWhenDone(true);
    }
    
    public Integer getStatus() {
    	return status;
    }

	public String getLastError() {
		return folderPrinter.getLastError();
	}
}